package xj.model.uml;

public enum CollectionType {

  Set, Bag, List, OrderedSet;

  public static String toString(CollectionType c) {
    if (c != null) {
      switch (c) {
      case Set:
	return "set";
      case Bag:
	return "bag";
      case List:
	return "list";
      case OrderedSet:
	return "ordered";
      }
    }
    return null;
  }

  public static CollectionType toCollectionType(String s) {
    if (s != null) {
      if ("set".equals(s)) {
	return CollectionType.Set;
      } else if ("bag".equals(s)) {
	return CollectionType.Bag;
      } else if ("ordered".equals(s)) {
	return CollectionType.OrderedSet;
      } else if ("list".equals(s)) {
	return CollectionType.List;
      } else {
	return CollectionType.Set;
      }
    }
    return null;
  }

  public static CollectionType toCollectionType(boolean ordered, boolean unique) {
    if (unique) {
      if (ordered) {
	return CollectionType.OrderedSet;
      } else {
	return CollectionType.Set;
      }
    } else {
      if (ordered) {
	return CollectionType.List;
      } else {
	return CollectionType.Bag;
      }
    }
  }

  public static boolean isOrdered(CollectionType c) {
    if (c != null) {
      switch (c) {
      case Set:
      case Bag:
	return false;
      case List:
      case OrderedSet:
	return true;
      }
    }
    return false;
  }

  public static boolean isUnique(CollectionType c) {
    if (c != null) {
      switch (c) {
      case Set:
      case OrderedSet:
	return true;
      case List:
      case Bag:
	return false;
      }
    }
    return true;
  }

}
